#ifndef COLLECTIONS_H
#define COLLECTIONS_H
#include <stdint.h>
#include "hashlib.h"
#include "li_list.h"
#include "li_tasks.h"
#include "li_pipe.h"

typedef char *str;
typedef void *Any;

#pragma region nextVersion
#ifdef nextVersion
typedef union UType
{
	int8_t vi8;
	char vchar;
	int16_t vi16;
	short vshort;
	int32_t vi32;
	int vint;
	float vfloat;

	int8_t *pi8;
	char *pchar;
	int16_t *pi16;
	short *pshort;
	int32_t *pi32;
	int *pint;
	int64_t *pi64;
	long *plong;
	float *pfloat;
	double *pdouble;
	void *pvoid;
#ifdef UType_ENABLE_x64
	int64_t vi64;
	long vlong;
	double vdouble;
#endif
} UType;

typedef struct LNode_t
{
	const char *key;
	int ext;
	HASH hash_code;

	UType val;
	struct LNode_t *next;
} LNode_t;
typedef LNode_t *LNode;

typedef struct
{
	LNode first;
	LNode last;
	unsigned int count;
} LList_t;
typedef LList_t *LList;
// LNode LNode_new(const char *key, UType val);
// void LNode_free(LNode node);
//
// int LList_append(LList list, const char *key, UType val);
// int LList_append2(LList list, LNode newNode);
//
// int LList_insert(LList list, LNode after, const char *key, UType val);
// int LList_insert2(LList list, LNode after, LNode newNode);
//
// int LList_remove(LList list, const char *key, UType val);
// UType LList_search(LList list, const char *key);
// LNode LList_index(LList list, const char *key);
#endif
#pragma endregion

typedef struct
{
	str name;
	HASH hashCode;
	Any data;
} Object_t;

typedef Object_t *Object;

typedef struct
{
	str name;
	HASH hashCode;
	const str doc;
	Arg_Tasks_def todo;
	uint8_t ext;
} Cmd_t;

typedef union
{
	float vf;
	int32_t vi;
	str vs;
	unsigned char vc;
	Any obj;
	void *pvoid;
	float *pf;
	int32_t *pi;
	str *ps;
	str pc;
} CVal;

typedef enum
{
	VarTypeFloat = 1,
	VarTypeInt = 2,
	VarTypeBool = 4,
	VartypeStr = 8,
	// assistant flags
	VarTypeArray = 16,
	VarTypeReadOnly = 32,
	VarTypePtr = 64,
	VarTypeTemp=128
} VarType;
#define _IS(v, vtype) (((v)->type) & (VarType##vtype))
#define _VAL(v) ((((v)->type) & VarTypeFloat) ? (v)->val.vf : (v)->val.vi)
typedef struct
{
	CVal val;
	union
	{
		uint32_t len;
		Any _ptr;
	};

	VarType type;
} Val_t;
typedef Val_t *Val;
typedef struct
{
	str name;
	HASH hashCode;
	union
	{
		Val_t val_t;
		struct
		{
			CVal val;
			uint32_t len;
			VarType type;
		};
	};
} Var_t;

typedef struct
{
	str name;
	HASH hashCode;
	void *ref;
	uint8_t narg;
	char type;
} Fun_t;
/*
typedef struct
{
	float PerdSec;
	int32_t count;
	Li_List cmds;
} Schedule_item_t;
typedef Schedule_item_t *Schedule_item;
*/

typedef Var_t *Var;
typedef Cmd_t *Cmd;
typedef Fun_t *Fun;

#endif